package com.labot.webapp.action;

import java.util.Date;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.context.SecurityContextHolder;

import com.labot.model.Area;
import com.labot.model.Envio;
import com.labot.model.Role;
import com.labot.model.User;


/**
 * Action for facilitating User Management feature.
 */
public class TareaAction extends BaseAction {
    private static final long serialVersionUID = 6776548938712115191L;
    
    private static String FIRMAS = "firmas";
    private static String ANALITICO = "analitico";
    private static String RECEPCIONISTA = "recepcionista";
    
    public String execute() {
        return SUCCESS;
    }
    
    public String cancel() {
    	return CANCEL;
    }


    /**
     * Fetch all Configs from database and put into local "configs" variable for retrieval in the UI.
     *
     * @return "success" if no exceptions thrown
     */
    public String comprobar() {
    	
    	User s = null;
    	try{
    		s = userManager.getUserByUsername(SecurityContextHolder.getContext().getAuthentication().getName());
    	}catch(Exception e){
    		super.addActionError("Error grave!");
    		return ERROR;
    	}
    	Set<Role> roles = s.getRoles();
    	for (Role r : roles) {
			if(r.getName().equals("ROLE_FIRMAS")){
				return FIRMAS;
			}
			if(r.getName().equals("ROLE_ANALITICO")){
				return ANALITICO;
			}
			if(r.getName().equals("ROLE_RECEPCIONISTA")){
				return RECEPCIONISTA;
			}
		}
    	
    	return SUCCESS;
    }
    
 
   


	
	
	
	

	
	

}
